﻿/*Sql server 数据库操作方法
 * 
 * 版权所有：hubs1
 * 开发部门：IT 
 * 程序负责：Andy.yang
 * 电话：021-61226688-5026
 * 其他联系：
 * Email：andy.yang@hubs1.net
 * MSN：yhailong@hotmail.com
 * QQ:9502855
 * 
 * 开发时间：2009年12月1日
 * 声明：仅限于您自己使用，不得进行商业传播，违者必究！
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;

namespace HBS.Data  
{
    /// <summary>
    /// errorlog 三种，Txt=文本日志、Mail=邮件、System=系统消息（暂未实现）
    /// </summary>
    public class ErrorLog
    {
        private static string logtype = "";//日志类型
        private static string erroremail = "";
        private static string logdirectory = "";

        static ErrorLog()
        {
            logtype = Utility.GetConfigInfo("LogType");
            erroremail = Utility.GetConfigInfo("errmail");
            logdirectory = Utility.GetConfigInfo("errdirectory");
        }

        public static void sendLog(System.Exception e1, string msg)
        {
            switch (logtype)
            {
                case "Txt":
                    if (logdirectory != "")
                        saveTxt(e1, msg);
                    break;
                case "System":
                    saveSystem(e1, msg);
                    break;
                case "Mail":
                    if (erroremail != "")
                        sendMail(e1, msg);
                    break;
            }
        }

        /// <summary>
        /// 文本日志
        /// </summary>
        /// <param name="e1"></param>
        /// <param name="msg"></param>
        private static void saveTxt(System.Exception e1, string msg)
        {
        //    string errmsg = DateTime.Now.ToString() + "：" + e1.Message + "\r\n" + msg;
        //    string filename = logdirectory + "\\" + DateTime.Now.ToShortDateString() + ".txt";
        //    MyFile.AppendFile(new StringBuilder(errmsg), filename);
        }

        /// <summary>
        /// 邮件日志
        /// </summary>
        /// <param name="e1"></param>
        /// <param name="msg"></param>
        private static void sendMail(System.Exception e1, string msg)
        {
            //string errmsg = e1.Message + "\r\n" + msg;
            //string fromurl = System.Web.HttpContext.Current.Request.Url.ToString();
            //CFun.sendemail("", erroremail, "数据库访问错误From:" + fromurl, errmsg, true, Encoding.UTF8);
        }

        /// <summary>
        /// 系统事件日志
        /// </summary>
        /// <param name="e1"></param>
        /// <param name="msg"></param>
        private static void saveSystem(System.Exception e1, string msg)
        {
          //  EventLog.WriteEntry("tademo error", "message" + e1.ToString(), EventLogEntryType.Warning, 80);
        }
    }
}
